import java.util.*;


public class Solution {

    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     *
     * @param folder string字符串一维数组
     * @return string字符串一维数组
     */
    public String[] removeSubfolders (String[] folder) {
        // write code here
        // ["/a","/a/b","/c/d","/c/d/e","/c/f"]
        // ["/a","/c/d","/c/f"]
        Set<String> set = new HashSet<>(Arrays.asList(folder));
        for (String s : folder) {
            String[] arr = s.split("/");
            StringBuilder str = new StringBuilder();
            for (int i = 1; i < arr.length - 1; i++) {
                str.append("/");
                str.append(arr[i]);
                if (set.contains(String.valueOf(str))) {
                    set.remove(s);
                }
            }
        }
        String[] ret = new String[set.size()];
        int i = 0;
        for (String s : folder) {
            if (set.contains(s)) {
                ret[i++] = s;
            }
        }
        return ret;
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        String[] ret = solution.removeSubfolders(new String[]{"/a","/a/b","/c/d","/c/d/e","/c/f"});
        for (String s : ret) {
            System.out.print(s + " ");
        }
    }


    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     *
     * @param nums int整型一维数组 目标数组
     * @param val int整型 需要移除的值
     * @return int整型
     */
    public int mySolution (int[] nums, int val) {
        // write code here
        int index = 0;
        int cur = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == val) {
                index = i;
                while (i < nums.length && nums[i] == val) {
                    i++;
                }
                nums[index++] = nums[i];
            } else {
                nums[index++] = nums[i];
            }
        }
        return index;
    }

}